﻿namespace Tool.Utils
{
    public static class TableHelper
    {
        public static string GetTableNameNew(string prefix, string key, int tableCount = 128)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return string.Empty;
            }
            char[] array = key?.ToCharArray();
            int num = 0;
            for (int i = 0; i < array.Length; i++)
            {
                num = 31 * num + array[i];
            }

            num = ((num < 0) ? Math.Abs(num) : num);
            if (string.IsNullOrWhiteSpace(prefix))
            {
                return $"{num % tableCount}";
            }

            return $"{prefix.TrimEnd(['_'])}_{Math.Abs(num) % tableCount}";
        }
    }
}
